<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>机器人</title>
<#include "/admin/main/include/link_head.ftl"/>
</head>

<body class="jr-body">
<div class="jr-main-content">
<@tags.pageHeading />
    <div class="wrapper">
        <div class="row">
            <div class="col-md-12">
            <@tags.table id="easyui-datagrid-left" options="url:'page?catId=${catId}',singleSelect:true">
                <@tags.th options="field:'name',width:300,sortable:false,align:'center'">机器人名称</@tags.th>
                <@tags.th options="field:'status',width:100,sortable:false,align:'center',formatter:'uiStatus'">机器人状态</@tags.th>
                <@tags.th options="field:'erweim',width:100,sortable:false,align:'center',formatter:'uiEwm'">
                    二维码</@tags.th>
                <@tags.th options="field:'op',width:100,sortable:false,align:'center',formatter:'uiOp'">操作</@tags.th>
            </@tags.table>
            <@tags.gridBtns id="tbMain" btns="add" />
            </div>
        </div>

    </div>
</div>
</body>
</html>
<#include "/admin/main/include/link_foot.ftl"/>
<script type="text/javascript">
    function uiOp(value, row, index) {
        if(row.status == 0 || row.status == '0'){
            return "<a href='javascript:start("+row.id+")' class='jr-grid-link'>启动</a>";
        }
        if(row.status == 2||row.status == '2') {
            return "<a href='javascript:start(" + row.id + ")' class='jr-grid-link'>重启</a>";
        }
        return "<a href='javascript:close("+row.id+")' class='jr-grid-link'>关闭</a>";
    }
    function close(id) {
        $.post("close",{id:id},function () {
            setTimeout(function () {
                window.location.reload();
            },1000);
        });
    }
    function  start(id) {
        $.post("start",{id:id},function () {
            setTimeout(function () {
                window.location.reload();
            },1000);
        });
    }
    function uiStatus(value, row, index) {
        if(value==0||value=='0'){
            return "关闭";
        }
        if(value==1||value=='1'){
            return "运行";
        }
        if(value==2||value=='2'){
            return "待扫码";
        }
        return "未知";
    }
    function uiEwm(value, row, index) {
        if (row.status == 2 || row.status == '2') {
            return "<a class='highslide' onclick='return hs.expand(this)' href='${imgPath}/" + row.uuid + "/temp/wxqr.png'><img src='${imgPath}/" + row.uuid + "/temp/wxqr.png' width='50' height='50' />";
        }
        if(row.status == 1 || row.status == '1'){
            return "运行中";
        }
        return "未启动";
    }
    $(function () {
        $(".jr-add").unbind("click");
        $(".jr-add").click(function () {
            $.post("save",{
                catId:${catId}
            },function(){
                setTimeout(function(){
                    window.location.reload()
                },1000);
            })
            return false;
        });
    });
</script>